﻿package view.popup
{
    import com.core.*;
    import com.core.display.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.text.*;
    import manager.*;
    import morn.core.components.*;
    import plugin.bagN.*;
    import plugin.storehouse.*;

    public class NewOpenLockUI2 extends View implements ILogger, IDialogUI
    {
        public var closeBtn:Button;
        public var sureBtn:Button;
        protected var uiXML:XML;
        private var toptext:TextField;
        private var bottomtext:TextField;
        private var middletext1:TextField;
        private var _type:int;

        public function NewOpenLockUI2()
        {
            this.uiXML = <View>r
n	t	t	t  <Image url=""png.common.s9_tishi"" x=""-1"" y=""0"" width=""300"" height=""186"" sizeGrid=""5,16,5,29""/>r
n	t	t	t  <Button skin=""png.common.btn_close_normal"" x=""275"" y=""0"" var=""closeBtn""/>r
n	t	t	t  <Button skin=""png.common.btn_usual_normal"" x=""105"" y=""141"" var=""sureBtn"" labelStroke=""1""/>r
n	t	t	t  <Image url=""png.common.bagcell"" scaleX=""0.68"" scaleY=""0.68"" x=""123"" y=""46""/>r
n	t	t	t  <Image url=""png.common.lock"" x=""135"" y=""54""/>r
n	t	t	t  <Image url=""png.common.s9_fenline"" x=""14"" y=""97"" width=""270"" sizeGrid=""5,16,5,29""/>r
n	t	t	t</View>")("<View>
			  <Image url="png.common.s9_tishi" x="-1" y="0" width="300" height="186" sizeGrid="5,16,5,29"/>
			  <Button skin="png.common.btn_close_normal" x="275" y="0" var="closeBtn"/>
			  <Button skin="png.common.btn_usual_normal" x="105" y="141" var="sureBtn" labelStroke="1"/>
			  <Image url="png.common.bagcell" scaleX="0.68" scaleY="0.68" x="123" y="46"/>
			  <Image url="png.common.lock" x="135" y="54"/>
			  <Image url="png.common.s9_fenline" x="14" y="97" width="270" sizeGrid="5,16,5,29"/>
			</View>;
            return;
        }// end function

        override protected function createChildren() : void
        {
            createView(this.uiXML);
            this.init();
            return;
        }// end function

        public function log(param1:String, param2:int = 0) : void
        {
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            return;
        }// end function

        public function init() : void
        {
            this.visible = false;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            this.toptext = new TextField();
            this.toptext.x = 60;
            this.toptext.y = 14;
            this.toptext.width = 200;
            this.toptext.height = 22;
            this.toptext.defaultTextFormat = new TextFormat("Verdana", 12);
            this.toptext.text = "你希望开启一行格子吗？";
            this.toptext.textColor = 16711680;
            this.addChild(this.toptext);
            this.bottomtext = new TextField();
            this.bottomtext.x = 95;
            this.bottomtext.y = 118;
            this.bottomtext.width = 200;
            this.bottomtext.height = 22;
            this.bottomtext.defaultTextFormat = new TextFormat("Verdana", 12);
            this.bottomtext.text = "(注:优先使用道具)";
            this.bottomtext.textColor = 26112;
            this.addChild(this.bottomtext);
            var _loc_1:* = new TextField();
            _loc_1.x = 40;
            _loc_1.y = 100;
            _loc_1.height = 22;
            _loc_1.defaultTextFormat = new TextFormat("宋体", 12);
            _loc_1.text = "开启当前行需要:";
            _loc_1.textColor = 11704940;
            this.addChild(_loc_1);
            var _loc_2:* = new TextField();
            _loc_2.x = 44 + 92 + 43;
            _loc_2.y = 100;
            _loc_2.height = 22;
            _loc_2.defaultTextFormat = new TextFormat("宋体", 12);
            _loc_2.text = "或";
            _loc_2.textColor = 16777215;
            this.addChild(_loc_2);
            this.sureBtn.label = "确认开启";
            this.sureBtn.labelColors = "0xb29a6c, 0xb29a6c, 0xb29a6c";
            this.sureBtn.addEventListener(MouseEvent.CLICK, this.onSureOpen);
            this.closeBtn.addEventListener(MouseEvent.CLICK, this.onClicked);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            return;
        }// end function

        public function show(param1:Object) : void
        {
            var _loc_4:Object = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            this._type = 1;
            if (param1)
            {
                this._type = int(param1);
            }
            this.visible = true;
            var _loc_2:int = 4;
            var _loc_3:int = 200;
            if (this._type == 1)
            {
                _loc_4 = ModelProxy.getValue("data", "bag");
                _loc_5 = _loc_4.maxcount;
                _loc_6 = _loc_5 / 7 - 5 + 1;
                _loc_2 = 7 * _loc_6;
                _loc_3 = 7 * 25 * _loc_6;
            }
            else
            {
                _loc_7 = ModelProxy.getValue("data", "openline");
                _loc_2 = 8 * _loc_7;
                _loc_3 = 8 * 25 * _loc_7;
            }
            if (this.middletext1 == null)
            {
                this.middletext1 = new TextField();
                this.middletext1.x = 154;
                this.middletext1.y = 100;
                this.middletext1.height = 22;
                this.middletext1.defaultTextFormat = new TextFormat("宋体", 12);
                this.middletext1.text = String(_loc_3) + "元宝   " + "消耗" + String(_loc_2) + "个扩充券";
                this.middletext1.textColor = MColor.New6;
                this.middletext1.autoSize = TextFieldAutoSize.CENTER;
                this.addChild(this.middletext1);
            }
            else
            {
                this.middletext1.text = String(_loc_3) + "元宝   " + "消耗" + String(_loc_2) + "个扩充券";
            }
            return;
        }// end function

        private function onSureOpen(event:MouseEvent) : void
        {
            if (this._type == 1)
            {
                PluginManager.instance.sendToServer("bag", CMDBag.Expansion, 7);
            }
            else if (this._type == 2)
            {
                PluginManager.instance.sendToServer("warehouse", CMDStorehouse.Expansion, 8);
            }
            this.close();
            return;
        }// end function

        private function onDown(event:MouseEvent) : void
        {
            event.stopImmediatePropagation();
            return;
        }// end function

        private function onClicked(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        public function close() : void
        {
            this.visible = false;
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            return;
        }// end function

    }
}
